﻿using System;
using WebAppDemo.Classes;

namespace WebAppDemo
{
    public partial class SessionToViewSate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnInit_Click(object sender, EventArgs e)
        {
            var p = new Person { Age = 12, Name = "chenxm" };
            Session["Demo"] = p;
            ViewState["Demo3"] = ((Person)Session["Demo"]).Clone();
        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            //step1
            var p = new Person { Age = 12, Name = "chenxm" };
            Session["Demo"] = p;
            ViewState["Demo3"] = ((Person)Session["Demo"]).Clone();

            //step2
            var pNew = (Person)ViewState["Demo3"];
            pNew.Name = "lilei";

            //step3
           var pNewN = (Person) Session["Demo"];
            txtViewState.Text = ((Person)ViewState["Demo3"]).Name;
            txtSession2.Text = pNewN.Name;
        }

        protected void btnChange_Click(object sender, EventArgs e)
        {
            var pNew = (Person)ViewState["Demo3"];
            pNew.Name = "lilei";
        }
    }

}
